/**
 * vespa
 */

var Vpa = {
    version:"1.0"
};

Vpa.apply = function(object, config, defaults) {
    if (defaults) {
        Vpa.apply(object, defaults);
    }

    if (object && config && typeof config === 'object') {
        for (i in config) {
            object[i] = config[i];
        }
    }

    return object;
};
Vpa.apply(Vpa, {
    /**
     * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
     * Usage:<pre><code>
     Ext.override(MyClass, {
     newMethod1: function(){
     // etc.
     },
     newMethod2: function(foo){
     // etc.
     }
     });
     </code></pre>
     * @param {Object} origclass The class to override
     * @param {Object} overrides The list of functions to add to origClass.  This should be specified as an object literal
     * containing one or more methods.
     * @method override
     */
    override : function(origclass, overrides) {
        if(overrides) {
            var p = origclass.prototype;
            for(var method in overrides) {
                p[method] = overrides[method];
            }
        }
    },
    /**
     * Extends one class with another class and optionally overrides members with the passed literal. This class
     * also adds the function "override()" to the class that can be used to override
     * members on an instance.
     * * <p>
     * This function also supports a 2-argument call in which the subclass's constructor is
     * not passed as an argument. In this form, the parameters are as follows:</p><p>
     * <div class="mdetail-params"><ul>
     * <li><code>superclass</code>
     * <div class="sub-desc">The class being extended</div></li>
     * <li><code>overrides</code>
     * <div class="sub-desc">A literal with members which are copied into the subclass's
     * prototype, and are therefore shared among all instances of the new class.<p>
     * This may contain a special member named <tt><b>constructor</b></tt>. This is used
     * to define the constructor of the new class, and is returned. If this property is
     * <i>not</i> specified, a constructor is generated and returned which just calls the
     * superclass's constructor passing on its parameters.</p></div></li>
     * </ul></div></p><p>
     * For example, to create a subclass of the Ext GridPanel:
     * <pre><code>
     MyGridPanel = Ext.extend(Ext.grid.GridPanel, {
     constructor: function(config) {
     // Your preprocessing here
     MyGridPanel.superclass.constructor.apply(this, arguments);
     // Your postprocessing here
     },

     yourMethod: function() {
     // etc.
     }
     });
     </code></pre>
     * </p>
     * @param {Function} subclass The class inheriting the functionality
     * @param {Function} superclass The class being extended
     * @param {Object} overrides (optional) A literal with members which are copied into the subclass's
     * prototype, and are therefore shared between all instances of the new class.
     * @return {Function} The subclass constructor.
     * @method extend
     */
    extend : function() {
        // inline overrides
        var io = function(o) {
            for(var m in o) {
                this[m] = o[m];
            }
        };
        var oc = Object.prototype.constructor;

        return function(sb, sp, overrides) {
            if(typeof sp == 'object') {
                overrides = sp;
                sp = sb;
                sb = overrides.constructor != oc ? overrides.constructor : function() {
                    sp.apply(this, arguments);
                };
            }
            var F = function() {}, sbp, spp = sp.prototype;
            F.prototype = spp;
            sbp = sb.prototype = new F();
            sbp.constructor=sb;
            sb.superclass = sbp.superclass=spp;
            if(spp.constructor == oc) {
                spp.constructor=sp;
            }
            sb.override = function(o) {
                Vpa.override(sb, o);
            };
            sbp.override = io;
            Vpa.override(sb, overrides);
            sb.extend = function(o) {
                Vpa.extend(sb, o);
            };
            return sb;
        };
    }()
});

Vpa.g_str_start_tag = '~~~vespa-str-start-tag~~~';
Vpa.g_str_end_tag = '~~~vespa-str-end-tag~~~';

Vpa.tag = {};
Vpa.doc = {};
Vpa.Markdown = {};
